﻿@model KL.Store.Web.Models.WishListDetailModel
@using KL.Store.Core
@{
    ViewBag.Title = "Arkadaşımın Listesi";
    Layout = "~/Views/Shared/" + Parameters.Layout + ".cshtml";
}
@section menu {
    @{ Html.RenderAction("Categories", "Partials"); }}
<div class="breadcrumb">
    <div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
        <a href="/" itemprop="url">
            <span itemprop="title">Anasayfa</span>
        </a>›
    </div>
    <div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">
        <a href="/WishLists/Index" itemprop="url">
            <span itemprop="title">Listelerim</span>
        </a>
    </div>
</div>
@Html.Raw(Model.FormMessage)
<h1>@Model.Name - @Model.ListName</h1>
<div class="cart-info">
    <div class="shop-cart">
        <table>
            <thead>
                <tr>
                    <td class="image">Resim
                    </td>
                    <td class="name">Açıklama
                    </td>
                    <td class="quantity">Adet
                    </td>
                    <td class="quantity">Alınan
                    </td>
                    <td class="price">Birim Fiyat
                    </td>
                    <td class="total" style="border-right: none;">Toplam
                    </td>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model.Products)
                {
                    <tr>
                        <td class="image">
                            <a id="pr_@item.ProductId" class="prdLink" href="@item.LinkUrl">
                                <img id="ip_@item.ProductId" src="@(Parameters.WebSiteImageUrl)/product-small/@(item.ProductId)_1.jpg" alt="@(item.ProductName.Replace("\"", ""))" /></a>
                        </td>
                        <td class="name">
                            <a id="pl_@item.ProductId" class="prdLink" href="@item.LinkUrl">@(item.ProductName)</a>
                        </td>
                        <td class="quantity">
                            @if (item.QtyPurchased >= @item.Qty)
                            {
                                @item.Qty.ToString("###,##0")
                            }
                            else
                            {
                                @item.Qty.ToString("###,##0")
@*<input type="text" id="qty_@(item.UserId)_@(item.ListId)_@(item.ProductId)" value="@item.Qty.ToString("#####")" size="1" />*@
                                <div class="cart">
                                    <a id="up_@(item.UserId)_@(item.ListId)_@(item.ProductId)" class="addToCart">
                                        @Html.Raw(Parameters.AddToCartButton)
                                        @*<img src="/Images/@(Parameters.Theme)/ToCart.png" title="Sepete Ekle" alt="Sepete Ekle" style="vertical-align: middle;" />*@
                                    </a>
                                </div>
                            }
                        </td>
                        <td class="quantity">
                            @item.QtyPurchased.ToString("###,##0")
                        </td>
                        <td class="price">
                            @item.Price.ToString("#.00")
                        </td>
                        <td class="total" style="border-right: 0;">
                            @((item.Price * item.Qty).ToString("#.00"))
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
</div>
<script type="text/javascript">
    $('a.addToCart').click(function () {
        var qsUserId = $(this).attr('id').split("_")[1];
        var qsListId = $(this).attr('id').split("_")[2];
        var qsProductId = $(this).attr('id').split("_")[3];
        var qsQty = 1; // $('#qty_' + qsUserId.toString() + "_" + qsListId.toString() + "_" + qsProductId.toString()).val();
        //$('#content').load('/Cart/Insert2', { ListOwnerId: qsUserId, ListId: qsListId, ProductId: qsProductId, Qty: qsQty }, function () { RefreshCartSummary(); });
        addToCart(qsUserId, qsListId, qsProductId);
        return false;
    });
    $('a.cgLink').click(function () {
        var qsId = $(this).attr('id').split("_")[1];
        $('#content').load('/Categories/Get', { id: qsId });
        return false;
    });
    $('a.prLink').click(function () {
        var qsId = $(this).attr('id').split("_")[1];
        $('#content').load('/Products/Get', { id: qsId });
        return false;
    });

    $('a.prdLink').click(function () {
        var qsId = $(this).attr('id').split("_")[1];
        $('#content').load('/Product/Get', { id: qsId });
        return false;
    });

    function RefreshCartSummary() {
        $('#cart').load('/Cart/GetSummary', {});
    }

    function addToCart(userId, listId, productId) {
        $("#dialog-form").load("/Cart/AddToCart", { UserId: userId, ListId: listId, ProductId: productId });
        $("#dialog-form").dialog("open");
    }
    $(function () {
        $("#dialog:ui-dialog").dialog("destroy");
        $("#dialog-form").dialog({
            autoOpen: false,
            height: 295,
            width: 450,
            modal: true,
            close: function (event, ui) {
                RefreshCartSummary();
            }
        });
    });
</script>
<div id="dialog-form" title="Sepete Ekle">
</div>
